package com.sunday.common.statemachine.study.e10_Deferred;

import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;

/**
 * TODO
 *
 * @author sunday
 * @since 2024/12/6
 */
public class Config6 extends StateMachineConfigurerAdapter<String, String> {

    @Override
    public void configure(StateMachineStateConfigurer<String, String> states)
            throws Exception {
        states
                .withStates()
                .initial("READY")
                .state("DEPLOY", "DEPLOY")
                .state("DONE")
                .and()
                .withStates()
                .parent("DEPLOY")
                .initial("DEPLOYPREPARE")
                .state("DEPLOYPREPARE", "DONE")
                .state("DEPLOYEXECUTE");
    }

    @Override
    public void configure(StateMachineTransitionConfigurer<String, String> transitions)
            throws Exception {
        transitions
                .withExternal()
                .source("READY").target("DEPLOY")
                .event("DEPLOY")
                .and()
                .withExternal()
                .source("DEPLOYPREPARE").target("DEPLOYEXECUTE")
                .and()
                .withExternal()
                .source("DEPLOYEXECUTE").target("READY")
                .and()
                .withExternal()
                .source("READY").target("DONE")
                .event("DONE")
                .and()
                .withExternal()
                .source("DEPLOY").target("DONE")
                .event("DONE");
    }
}